import request from '@/utils/request'
import qs from 'qs'

export const addDictionary = (pid, code, name, codesort = 0) => {
  const data = {
    pid,
    code,
    name,
    codesort
  }
  return request({
    url: '/admin/dictionary/add',
    method: 'post',
    data: qs.stringify(data)
  })
}

export const checkCode = (code) => {
  const data = {
    code
  }
  return request({
    url: '/admin/dictionary/unique',
    method: 'get',
    params: data
  })
}
export const update = (id, name, codesort = 0, state = 1) => {
  const data = {
    id,
    name,
    codesort,
    state
  }
  return request({
    url: '/admin/dictionary/update',
    method: 'post',
    data: qs.stringify(data)
  })
}
export const find = (id) => {
  const data = {
    id
  }
  return request({
    url: '/admin/dictionary/findById',
    method: 'get',
    params: data
  })
}
export const findChild = (pid, iDisplayStart = 0, size = '', name = '') => {
  const data = {
    iDisplayStart,
    size,
    name,
    pid
  }
  return request({
    url: '/admin/dictionary/find',
    method: 'post',
    data: qs.stringify(data)
  })
}
export const deleteType = (id) => {
  const data = {
    id
  }
  return request({
    url: '/admin/dictionary/delete',
    method: 'post',
    data: qs.stringify(data)
  })
}
export const addStyle = (code, title, content) => {
  const data = {
    code,
    title,
    content
  }
  return request({
    url: '/admin/content/add',
    method: 'post',
    data: qs.stringify(data)
  })
}
export const updateStyle = (title, content, id) => {
  const data = {
    id,
    title,
    content
  }
  return request({
    url: '/admin/content/update',
    method: 'post',
    data: qs.stringify(data)
  })
}
export const listStyle = (iDisplayStart = 0, iDisplayLength = 10, title, code) => {
  const data = {
    iDisplayStart,
    iDisplayLength,
    title,
    code
  }
  return request({
    url: '/admin/content/find',
    method: 'post',
    data: qs.stringify(data)
  })
}
export const detailContent = (id) => {
  return request({
    url: '/admin/content/findById',
    method: 'get',
    params: { id }
  })
}
